#pragma once
#include"HashBucket.h"

namespace bit
{
	template<class K,class Hash = HashFunc<K>>
	class unordered_set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}

		};
	public:
		typedef typename HashBucket<K,const K, SetKeyOfT,Hash>::Iterator iterator;

		typedef typename HashBucket<K,const K, SetKeyOfT,Hash>::Const_Iterator const_iterator;
		iterator begin()
		{
			return _hb.Begin();
		}

		iterator end()
		{
			return _hb.End();
		}

		const_iterator begin()const
		{
			return _hb.Begin();
		}

		const_iterator end()const
		{
			return _hb.End();
		}
		pair<iterator,bool> insert(const K& k)
		{
			return _hb.Insert(k);
		}
		iterator find(const K& key)
		{
			return _hb.Find(key);
		}

		bool erase(const K& key)
		{
			return _hb.Erase(key);
		}

	private:
		HashBucket<K,const K, SetKeyOfT,Hash> _hb;
	};

	void Print(const unordered_set<int>& s)
	{
		unordered_set<int>::const_iterator it = s.begin();
		while (it != s.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}

	void test_set()
	{
		unordered_set<int> s;
		int a[] = { 4,2,6,1,3,5,15,7,16,14 };
		
		for (auto e : a)
		{
			s.insert(e);
		}

		for (auto e : s)
		{
			cout << e << " ";
		}

		cout << endl;

		unordered_set<int>::iterator it = s.begin();

		while (it != s.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;
		Print(s);
		
	}
}

